#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dialog)
{
    ui->setupUi(this);
}

Dialog::~Dialog()
{
    delete ui;
}


void Dialog::on_pushButton_clicked()
{
LookupHostInfoFunc();

}

void Dialog::on_pushButton_2_clicked()
{
  ui->plainTextEdit->clear();
}
QString getprotocol(QHostAddress&hs)
{
    if(QAbstractSocket::IPv4Protocol==hs.protocol())
    {
        return QString("IPV4");
    }
    else if(QAbstractSocket::IPv6Protocol==hs.protocol())
    {
        return QString("IPV6");
    }
    else if(QAbstractSocket::AnyIPProtocol==hs.protocol())
    {
        return QString("any IP");

    }
    else
    {
        return "Unknown Network Layer Protocol";
    }
}
void Dialog::LookupHostInfoFunc()
{
    QHostInfo host=QHostInfo::fromName(ui->lineEdit->text());

    QList<QHostAddress> addresslist=host.addresses();
    for(int i=0;i<addresslist.count();i++)
    {
        QHostAddress host=addresslist.at(i);
         ui->plainTextEdit->appendPlainText("IP协议"+getprotocol(host));
         ui->plainTextEdit->appendPlainText("本地IP地址："+host.toString());


    }
}

